<template>
  <div>
    <h1>我是后台路由页面</h1>
    <el-button @click="logout" type="info">退出</el-button>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {}
  },
  methods: {
    logout() {
      //实现账号退出功能
      window.sessionStorage.removeItem("token")
      this.$router.push("/login")
    },
  },
  // 设置组件内路由守卫
  beforeRouteEnter(to, from, next) {
    // console.log("我被调用了");
    // console.log(to);
    // console.log(from);
    const tokenstr = window.sessionStorage.getItem("token")
    // console.log(tokenstr);
    if (tokenstr) {
      next()
    } else {
      next("/login")
    }
  },
}
</script>

<style>
</style>